[R] multiple functions in one R script
Posted
by Philipp
on Stack Overflow
See other posts from Stack Overflow
or by Philipp
Published on 2010-06-16T12:58:42Z
Indexed on
2010/06/16
13:02 UTC
Read the original article
Hit count: 261
Hi,
I guess it's a stupid question, but I don't get it :-(
I wrote an R script, which creates heatmaps out of xls files. I am calling this R script with a Perl system call and pass over all the arguments. This all works fine.
Now I wanted to make the R script less confusing by writing different functions in the R script, for example:
args <- commandArgs(TRUE)
parsexls <- function(filepath)
{ data <- read.xls(...)
assign("data", data, globalenv()) }
reorder <- function(var)
{ data <- data[order...]
assign("data", data, globalenv()) }
When I want to call the functions with
parsexls(args[1])
reorder(args[2])
nothing happens.
But when I place the parsexls(args[1])
in the script between the two functions shown above, the file is parsed correctly! The reorder(args[2])
seems never to be read.
Any ideas what I am doing wrong?
Phil
© Stack Overflow or respective owner